package com.dgshanger.sanhxiaofeisc.ui.home.activity

import android.content.Intent
import android.view.View
import android.widget.LinearLayout
import com.dgshanger.sanhxiaofeisc.MainActivity
import com.dgshanger.sanhxiaofeisc.R
import com.dgshanger.sanhxiaofeisc.common.Constants
import com.dgshanger.sanhxiaofeisc.entity.PayResultEntity
import com.dgshanger.sanhxiaofeisc.mvp.contract.PayResultContract
import com.dgshanger.sanhxiaofeisc.mvp.presenter.PayResultPresenter
import com.dgshanger.sanhxiaofeisc.ui.home.utils.ImageLoader
import com.dgshanger.sanhxiaofeisc.ui.person.ServiceActivity
import com.xx.baseuilibrary.mvp.lcec.BaseMvpLcecActivity
import kotlinx.android.synthetic.main.activity_pay_result.*

/**
 * Created by JacobHHH on 2018/4/22.
 */
class PayResultActivity : BaseMvpLcecActivity<LinearLayout,PayResultEntity,PayResultContract.Model, PayResultContract.View, PayResultPresenter>(), PayResultContract.View, View.OnClickListener {


    private lateinit var mOrderId : String

    override fun createPresenter(): PayResultPresenter = PayResultPresenter()

    override fun getActivityLayoutId(): Int = R.layout.activity_pay_result

    override fun initData() {
        super.initData()
        mOrderId=intent.getStringExtra("orderId")
        initView()
        loadData(true)
    }

    private fun initView() {
        tv_comment.setOnClickListener(this)
        tv_order_query.setOnClickListener(this)
        ib_back22.setOnClickListener(this)
    }

    override fun initEvent() {

    }

    override fun onClick(view: View?) {
        when(view!!.id){
            R.id.tv_comment->{//立即评论
                val intent = Intent(mContext, GradeActivity::class.java)
                intent.putExtra("image",mData.shop_menu_img)
                intent.putExtra("order_sn",mData.order_sn)
                intent.putExtra("name",mData.shop_name)
                intent.putExtra("address",mData.shop_address)
                startActivity(intent)
            }
            R.id.tv_order_query->{//该订单有疑问
                val intent = Intent(mContext, ServiceActivity::class.java)
                startActivity(intent)
            }
            R.id.ib_back22->{
                startActivity(MainActivity::class.java)
            }
        }
    }

    override fun loadData(refresh: Boolean) {
        presenter.loadData(refresh,mOrderId)
    }

    private lateinit var mData : PayResultEntity
    override fun setData(data: PayResultEntity?) {
        mData=data!!
        showContent()
        ImageLoader.loadToUrl(mContext,iv_shop,Constants.getBaseUrl()+data?.shop_menu_img)
        tv_shop.text=data!!.shop_name
        tv_address.text=data.shop_address
        tv_price.text="￥ "+data.order_amount
        tv_order_id.text=data.order_sn
        tv_time.text=data.pay_time
        tv_describe.text="        "+data.bill_remark
    }


}